scale: Bring back marks-related style classes
authorMatthias Clasen <mclasen@redhat.com>
Wed, 18 May 2016 16:59:39 +0000 (12:59 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Wed, 18 May 2016 16:59:39 +0000 (12:59 -0400)
It turns out that it is too hard (and in some cases, impossible)
to get this information from node positioning, so bring back the
.scale-has-marks-above/below style classes on the main node.

This should allow us to fix the 'pointy sliders'.

https://bugzilla.gnome.org/show_bug.cgi?id=766440

gtk/gtkscale.c

index 6d71292e14ad0894bc5527a845899a5e4fa10915..5b3ff9b8cffd93a0e70ace49fb47572f21e80be4 100644 (file)
  * # CSS nodes
  *
  * |[<!-- language="plain" -->
- * scale[.fine-tune]
+ * scale[.fine-tune][.scale-has-marks-above][.scale-has-marks-below]
  * ├── marks.top
  * │   ├── mark
  * │   ┊    ├── [label]
  * │   ┊    ╰── indicator
  * ┊   ┊
  * │   ╰── mark
+ * ├── [value]
  * ├── contents
  * │   ╰── trough
  * │       ├── slider
  * has a subnode named label. When the mark is either above or left of the
  * scale, the label subnode is the first when present. Otherwise, the indicator
  * subnode is the first.
+ *
+ * The main CSS node gets the 'scale-has-marks-above' and/or 'scale-has-marks-below'
+ * style classes added depending on what marks are present.
+ *
+ * If the scale is displaying the value (see #GtkScale:draw-value), there is
+ * subnode with name value.
  */
 
 
@@ -2003,6 +2010,7 @@ void
 gtk_scale_clear_marks (GtkScale *scale)
 {
   GtkScalePrivate *priv;
+  GtkStyleContext *context;
 
   g_return_if_fail (GTK_IS_SCALE (scale));
 
@@ -2018,6 +2026,10 @@ gtk_scale_clear_marks (GtkScale *scale)
     gtk_css_node_set_parent (gtk_css_gadget_get_node (priv->bottom_marks_gadget), NULL);
   g_clear_object (&priv->bottom_marks_gadget);
 
+  context = gtk_widget_get_style_context (GTK_WIDGET (scale));
+  gtk_style_context_remove_class (context, GTK_STYLE_CLASS_SCALE_HAS_MARKS_BELOW);
+  gtk_style_context_remove_class (context, GTK_STYLE_CLASS_SCALE_HAS_MARKS_ABOVE);
+
   _gtk_range_set_stop_values (GTK_RANGE (scale), NULL, 0);
 
   gtk_widget_queue_resize (GTK_WIDGET (scale));
@@ -2060,6 +2072,7 @@ gtk_scale_add_mark (GtkScale        *scale,
   gdouble *values;
   gint n, i;
   GtkCssNode *widget_node, *marks_node;
+  GtkStyleContext *context;
 
   g_return_if_fail (GTK_IS_SCALE (scale));
 
@@ -2184,6 +2197,12 @@ gtk_scale_add_mark (GtkScale        *scale,
 
   g_free (values);
 
+  context = gtk_widget_get_style_context (GTK_WIDGET (scale));
+  if (priv->top_marks_gadget)
+    gtk_style_context_add_class (context, GTK_STYLE_CLASS_SCALE_HAS_MARKS_ABOVE);
+  if (priv->bottom_marks_gadget)
+    gtk_style_context_add_class (context, GTK_STYLE_CLASS_SCALE_HAS_MARKS_BELOW);
+
   gtk_widget_queue_resize (widget);
 }